package so.sao.code.service.domain.handler.query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import so.sao.code.service.domain.event.query.GetEnterpriseUrlsEvent;
import so.sao.code.service.repository.EnterpriseDomainDao;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2017/10/20.
 */
@Component
public class GetEnterpriseUrlsHandler {
    @Autowired
    EnterpriseDomainDao enterpriseDomainDao;
    @Value("${sao.code.key.default-domain}")
    private String defaultDomain;

    @EventListener
    public void getUrl(GetEnterpriseUrlsEvent enterpriseUrlsEvent) {
        List<String> urls = enterpriseDomainDao.findByEseId(enterpriseUrlsEvent.getEseId());
        urls.add(defaultDomain);
        Collections.reverse(urls);
        enterpriseUrlsEvent.setResult(urls);
    }
}
